/*
 *  This file is part of libgolf.
 * 
 *  libgolf is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  libgolf is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with libgolf.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * CxxTest reference: http://cxxtest.sourceforge.net/guide.html
 */

#ifndef _TESTRATING_H
#define _TESTRATING_H

#include <cxxtest/TestSuite.h>
#include "../gensrc/Rating.h"

class testRating : public CxxTest::TestSuite
{
    public:
        void test_rating_ctor_no_args(void)
        {
            Rating  rtn;
            
            TS_ASSERT_EQUALS(rtn.get_SR(), 113u);
            TS_ASSERT_EQUALS(rtn.get_CR(), 72.0);
        }
        
        void test_rating_ctor_with_args(void)
        {
            Rating  rtn(69.3, 121u);
            
            TS_ASSERT_EQUALS(rtn.get_SR(), 121u);
            TS_ASSERT_EQUALS(rtn.get_CR(), 69.3);
        }
        
        void test_rating_ctor_range_checking(void)
        {
            Rating  lower(40.0, 54u);
            Rating  upper(40.1, 156u);
            
            TS_ASSERT_EQUALS(lower.get_CR(), 40.1);
            TS_ASSERT_EQUALS(lower.get_SR(), 55u);
            
            TS_ASSERT_EQUALS(upper.get_SR(), 155u);
        }
        
        void test_rating_ctor_quantization(void)
        {
            Rating  up(74.28, 113u);
            Rating  dn(74.23, 113u);
            Rating  even_up(74.35, 113u);
            Rating  even_dn(74.25, 113u);
            
            TS_ASSERT_EQUALS(up.get_CR(), 74.3);
            TS_ASSERT_EQUALS(dn.get_CR(), 74.2);
            TS_ASSERT_EQUALS(even_up.get_CR(), 74.4);
            TS_ASSERT_EQUALS(even_dn.get_CR(), 74.2);
        }
        
        void test_rating_cctor(void)
        {
            Rating  rtn(69.3, 121u);
            Rating  copy(rtn);
            
            rtn.set_SR(122u);
            TS_ASSERT_EQUALS(copy.get_SR(), 121u);
            TS_ASSERT_EQUALS(copy.get_CR(), 69.3);
        }
        
        void test_rating_operator_copy(void)
        {
            Rating  rtn(69.3, 121u);
            Rating  copy = rtn;
            
            rtn.set_SR(122u);
            TS_ASSERT_EQUALS(copy.get_SR(), 121u);
            TS_ASSERT_EQUALS(copy.get_CR(), 69.3);
        }
        
        void test_operator_equivalence(void)
        {
            Rating  p(69.3, 121u);
            Rating  q(69.4, 121u);
            
            TS_ASSERT_DIFFERS(p, q);
            q.set_CR(69.3);
            TS_ASSERT_EQUALS(p, q);
        }

        void test_get_set_SR(void)
        {
            Rating  rtn;

            rtn.set_SR(155u);
            TS_ASSERT_EQUALS(rtn.get_SR(), 155u);

            rtn.set_SR(156u);
            TS_ASSERT_EQUALS(rtn.get_SR(), 155u);

            rtn.set_SR(55u);
            TS_ASSERT_EQUALS(rtn.get_SR(), 55u);

            rtn.set_SR(54u);
            TS_ASSERT_EQUALS(rtn.get_SR(), 55u);
        }
        
        void test_get_set_CR(void)
        {
            Rating rtn;
            
            rtn.set_CR(73.2);
            TS_ASSERT_EQUALS(rtn.get_CR(), 73.2);
            
            rtn.set_CR(40.1);
            TS_ASSERT_EQUALS(rtn.get_CR(), 40.1);

            rtn.set_CR(40.0);
            TS_ASSERT_EQUALS(rtn.get_CR(), 40.1);
        }
        
        void test_set_CR_quantize(void)
        {
            Rating rtn;
            
            rtn.set_CR(73.28);
            TS_ASSERT_EQUALS(rtn.get_CR(), 73.3);

            rtn.set_CR(73.21);
            TS_ASSERT_EQUALS(rtn.get_CR(), 73.2);

            rtn.set_CR(73.25);
            TS_ASSERT_EQUALS(rtn.get_CR(), 73.2);

            rtn.set_CR(73.35);
            TS_ASSERT_EQUALS(rtn.get_CR(), 73.4);
        }
};

#endif /* _TESTRATING_H */
